
<template>
  <div>
    <b-card>
      <template #header>
        <b-button-group>
          <b-button size="sm" v-b-modal.form>上传</b-button>
        </b-button-group>
      </template>
      <b-table :fields="fields" :items="items">
        <template #cell(op)="{ item }">
          <b-button @click="remove(item)">删除</b-button>
        </template>
      </b-table>
    </b-card>
    <b-modal id="form" @ok="submit">
      <b-form>
        <b-form-group label="选择文件">
          <haier-file :files="form.files"></haier-file>
        </b-form-group>
      </b-form>
    </b-modal>
  </div>
</template>

<script>
/*eslint-disable */
import File from "@/components/File.vue";

export default {
  data() {
    return {
      assets: {},
      form: {
        files: [],
      },
      fields: [
        { key: "content", label: "名称" },
        { key: "type", label: "类型" },
        { key: "op", label: "操作" },
      ],
      items: [],
    };
  },
  methods: {
    submit() {
      this.$haier.upload("admin/assets", this.form).then(({ data }) => {
        this.$haier
          .post(`admin/customer/assets/${this.assets.id}`, {
            assets: data.map((item) => item.saveName),
          })
          .then(() => {
            this.load();
          });
      });
    },
    load() {
      this.$haier
        .get("admin/customer/assets", { id: this.assets.id })
        .then(({ data }) => {
          this.items = data.assets;
        });
    },
    remove(item) {
      this.$haier
        .delete(`admin/customer/assets/${this.assets.id}`, { aid: item.id })
        .then(() => {
          this.load();
        });
    },
  },
  created() {
    this.assets = this.$route.query;
    this.load();
  },
  components: {
    "haier-file": File,
  },
};
</script>

<style scoped>
</style>
